package com.briup.jd2407cms.utils;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.converters.ReadConverterContext;
import com.alibaba.excel.converters.WriteConverterContext;
import com.alibaba.excel.enums.CellDataTypeEnum;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import org.springframework.beans.factory.parsing.ReaderContext;

/**
 * @BelongsProject: cms2
 * @BelongsPackage: com.briup.jd2407cms.utils
 * @Author: wangjie
 * @CreateTime: 2024-11-21  15:19
 * @Description: TODO
 * @Version: 1.0
 */
public class DeletedConverter implements Converter<Integer> {
    @Override
    public Class supportJavaTypeKey() {
        return Integer.class;
    }

    @Override
    public CellDataTypeEnum supportExcelTypeKey() {
        return CellDataTypeEnum.STRING;
    }

    @Override
    public Integer convertToJavaData(ReadCellData cellData, ExcelContentProperty excelContentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return cellData.getStringValue().equals("被删除")?1:0;
    }

    @Override
    public Integer convertToJavaData(ReadConverterContext<?> context) throws Exception {
        return context.getReadCellData().getStringValue().equals("被删除")?1:0;
    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        return new WriteCellData<>(value.equals(0)?"未被删除":"被删除");
    }

    @Override
    public WriteCellData<?> convertToExcelData(WriteConverterContext<Integer> context) throws Exception {
        return new WriteCellData<Integer>(context.getValue().equals(1)?"被删除":"未被删除");
    }
}
